package com.eshop.controller.good;

import com.eshop.pojo.Good;
import com.eshop.pojo.RespBean;
import com.eshop.pojo.RespPageBean;
import com.eshop.service.GoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "冻结商品相关")
@RestController
@RequestMapping("/good/freezed")
public class GoodFreezedController {
    @Autowired
    GoodService goodService;

    //分页获取已冻结商品列表
    @ApiOperation("分页获取已冻结商品列表")
    @GetMapping("/")
    public RespPageBean getFreezedGoodByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                          @RequestParam(defaultValue = "8") Integer size, Good good) {
        return goodService.getFreezedGoodByPage(currentPage, size,good);
    }

    //解冻商品
    @ApiOperation("解冻商品")
    @PutMapping("/unfreezeGood/{id}")
    public RespBean unfreezeGood(@PathVariable int id){
        if (goodService.recoverGood(id) == 1){
            return RespBean.success("解冻成功！");
        }
        return RespBean.error("解冻失败！");
    }
}
